<?php

namespace app\common\model\order;

use think\Model;


class Goods extends Model
{





    // 表名
    protected $name = 'order_goods';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'goods_type_text',
        'spec_array',
        'image_str',
    ];
    public function getImageStrAttr($v, $d)
    {
        return $d['image'] ? cdnurl($d['image'], true) : '';
    }
    public function getSpecArrayAttr($v, $d)
    {

        return json_decode($d['spec_info'], true);
    }

    public function getGoodsTypeList()
    {
        return ['1' => __('Goods_type 1'), '2' => __('Goods_type 2')];
    }


    public function getGoodsTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['goods_type']) ? $data['goods_type'] : '');
        $list = $this->getGoodsTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function goods()
    {
        return $this->belongsTo('app\common\model\goods\Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function spec()
    {
        return $this->belongsTo('app\common\model\goods\Spec', 'spec_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function order()
    {
        return $this->belongsTo('app\common\model\order\Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
